<HTML>
<HEAD>
<TITLE>map</TITLE>
<LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Rogue Wave Standard Stylesheet"></HEAD>
<BODY BGCOLOR=#FFFFFF>
<A HREF="map-h.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="mask-array.html"><IMG SRC="images/bnext.gif" WIDTH=25 HEIGHT=21 ALT="Next file" BORDER=O></A><DIV CLASS="DOCUMENTNAME"><B>Rogue Wave C++ Standard Library Reference Guide</B></DIV>
<H2>map</H2>
<P><B>Module:</B>&nbsp;&nbsp;Standard C++ Library&nbsp;&nbsp;&nbsp;<B>Library:</B>&nbsp;&nbsp;<A HREF="2-7.html">Containers</A></P>

<PRE><HR><B><I>Does not inherit</I></B><HR></PRE>

<UL>
<LI><A HREF="#sec1">Local Index</A></LI>
<LI><A HREF="#sec2">Summary</A></LI>
<LI><A HREF="#sec3">Synopsis</A></LI>
<LI><A HREF="#sec4">Description</A></LI>
<LI><A HREF="#sec5">Interface</A></LI>
<LI><A HREF="#sec6">Constructors</A></LI>
<LI><A HREF="#sec7">Allocators</A></LI>
<LI><A HREF="#sec8">Iterators</A></LI>
<LI><A HREF="#sec9">Member Operators</A></LI>
<LI><A HREF="#sec10">Member Functions</A></LI>
<LI><A HREF="#sec11">Nonmember Operators</A></LI>
<LI><A HREF="#sec12">Specialized Algorithms</A></LI>
<LI><A HREF="#sec13">Example</A></LI>
<LI><A HREF="#sec14">Warnings</A></LI>
<LI><A HREF="#sec15">See Also</A></LI>
<LI><A HREF="#sec16">Standards Conformance</A></LI>
</UL>
<A NAME="sec1"><H3>Local Index</H3></A>
<H4>Members</H4>
<UL><TABLE CELLPADDING=3>
<TR><TD VALIGN=top>
<A HREF="#idx840">begin()</A><BR>
<A HREF="#idx850">clear()</A><BR>
<A HREF="#idx851">count()</A><BR>
<A HREF="#idx852">empty()</A><BR>
<A HREF="#idx842">end()</A><BR>
<A HREF="#idx853">equal_range()</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx855">erase()</A><BR>
<A HREF="#idx858">find()</A><BR>
<A HREF="#idx839">get_allocator()</A><BR>
<A HREF="#idx860">insert()</A><BR>
<A HREF="#idx862">key_comp()</A><BR>
<A HREF="#idx863">lower_bound()</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx836">map()</A><BR>
<A HREF="#idx865">max_size()</A><BR>
<A HREF="#idx848">operator=()</A><BR>
<A HREF="#idx849">operator[]()</A><BR>
<A HREF="#idx844">rbegin()</A><BR>
<A HREF="#idx846">rend()</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx866">size()</A><BR>
<A HREF="#idx867">swap()</A><BR>
<A HREF="#idx868">upper_bound()</A><BR>
<A HREF="#idx870">value_comp()</A><BR>
</TD></TR>
</TABLE></UL>
<H4>Non-Members</H4>
<UL><TABLE CELLPADDING=3>
<TR><TD VALIGN=top>
<A HREF="#idx872">operator!=()</A><BR>
<A HREF="#idx874">operator&gt;()</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx876">operator&gt;=()</A><BR>
<A HREF="#idx873">operator&lt;()</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx875">operator&lt;=()</A><BR>
<A HREF="#idx871">operator==()</A><BR>
</TD>
<TD VALIGN=top></TD></TR>
</TABLE></UL>

<A NAME="sec2"><H3>Summary</H3></A>
<P>An associative container with access to non-key values using unique keys. A <B><I>map</I></B> supports bidirectional iterators.</P>
<A NAME="sec3"><H3>Synopsis</H3></A>

<PRE>#include &lt;map&gt;

namespace std {
  template &lt;class Key, class T, class Compare = less&lt;Key&gt;,
            class Allocator = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
  class map;
}
</PRE>
<A NAME="sec4"><H3>Description</H3></A>
<P><B><I>map</I></B> gives fast access to stored values of type <SAMP>T</SAMP> that are indexed by unique keys of type <B><I>Key</I></B>. The default operation for key comparison is the <SAMP>&lt;</SAMP> operator. </P>
<P><B><I>map</I></B> has bidirectional iterators that point to an instance of <SAMP>pair&lt;const Key x, T y&gt;</SAMP> where <SAMP>x</SAMP> is the key and <SAMP>y</SAMP> is the stored value associated with that key. The definition of <B><I>map</I></B> includes a <SAMP>typedef</SAMP> to this pair called <SAMP>value_type</SAMP>. </P>
<P>The types used for both the template parameters <SAMP>Key</SAMP> and<SAMP> T</SAMP> must include the following (where <SAMP>T</SAMP> is the <SAMP>type</SAMP>, <SAMP>t</SAMP> is a <SAMP>value</SAMP> of <SAMP>T</SAMP> and <SAMP>u</SAMP> is a <SAMP>const</SAMP> <SAMP>value</SAMP> of <SAMP>T</SAMP>): </P>
<P><TABLE CELLPADDING=3 BORDER=0>
<TR CLASS="LIST"><TD VALIGN="top" CLASS="LIST"><P CLASS="LIST">Copy constructors  </P></TD>
<TD CLASS="LIST"><P CLASS="LIST"><SAMP>T(t)</SAMP> and <SAMP>T(u)</SAMP></P></TD></TR>
<TR CLASS="LIST"><TD VALIGN="top" CLASS="LIST"><P CLASS="LIST">Destructor  </P></TD>
<TD CLASS="LIST"><P CLASS="LIST"><SAMP>t.~T()</SAMP></P></TD></TR>
<TR CLASS="LIST"><TD VALIGN="top" CLASS="LIST"><P CLASS="LIST">Address of  </P></TD>
<TD CLASS="LIST"><P CLASS="LIST"><SAMP>&amp;t</SAMP> and <SAMP>&amp;u</SAMP> yielding <SAMP>T*</SAMP> and <SAMP>const T*</SAMP> respectively</P></TD></TR>
<TR CLASS="LIST"><TD VALIGN="top" CLASS="LIST"><P CLASS="LIST">Assignment  </P></TD>
<TD CLASS="LIST"><P CLASS="LIST"><SAMP>t = a</SAMP> where <SAMP>a</SAMP> is a (possibly <SAMP>const</SAMP>) value of <SAMP>T</SAMP></P></TD></TR>
</TABLE></P>
<P>The type used for the <SAMP>Compare</SAMP> template parameter must satisfy the requirements for binary functions. </P>
<A NAME="sec5"><H3>Interface</H3></A>

<UL><PRE>namespace std {

  template &lt;class Key, class T, class Compare = less&lt;Key&gt;, 
            class Allocator = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
  class map {

    public:

      // types
      typedef Key key_type;
      typedef typename Allocator::pointer pointer;
      typedef typename Allocator::const_pointer const_pointer;
      typedef T mapped_type;
      typedef pair&lt;const Key, T&gt; value_type;
      typedef Compare key_compare;
      typedef Allocator allocator_type;
      typedef typename Allocator::reference reference;
      typedef typename Allocator::const_reference
        const_reference;
      class iterator;
      class const_iterator;
      typedef typename
           Allocator::size_type size_type;
      typedef typename
           Allocator::difference_type  difference_type;
      typedef typename Allocator::pointer pointer;
      typedef typename Allocator::const_pointer const_pointer;
      typedef typename std::reverse_iterator&lt;iterator&gt;
           reverse_iterator;
      typedef typename std::reverse_iterator&lt;const_iterator&gt;
                         const_reverse_iterator;

      class value_compare
        : public binary_function&lt;value_type, value_type, bool&gt;
      {
        friend class map&lt;Key, T, Compare, Allocator&gt;;

          protected :
          Compare comp;
          value_compare(Compare c): comp(c) {}
     
          public :
          bool operator() (const value_type&amp;,
                           const value_type&amp;) const;
      };

      // Construct/Copy/Destroy

      explicit map (const Compare&amp; = Compare(),
                    const Allocator&amp; = Allocator ());
      template &lt;class InputIterator&gt;
      map(InputIterator, InputIterator,
          const Compare&amp; = Compare(),
          const Allocator&amp; = Allocator ());
      map(const map&lt;Key, T, Compare, Allocator&gt;&amp;);
      map
      operator=(const map&lt;Key, T, Compare, Allocator&gt;&amp;);
      allocator_type get_allocator() const;

      // Iterators

      iterator begin();
      const_iterator begin() const;
      iterator end();
      const_iterator end() const;
      reverse_iterator rbegin();
      const_reverse_iterator rbegin() const;
      reverse_iterator rend();
      const_reverse_iterator rend() const;

      // Capacity

      bool empty() const;
      size_type size() const;
      size_type max_size() const;

      // Element Access

      mapped_type&amp; operator[] (const key_type&amp;);

      // Modifiers

      pair&lt;iterator, bool&gt; insert (const value_type&amp;);
      iterator insert (iterator, const value_type&amp;);
      template &lt;class InputIterator&gt;
      void insert (InputIterator, InputIterator);

      void erase (iterator);
      size_type erase (const key_type&amp;);
      void erase (iterator, iterator);
      void swap (map&lt;Key, T, Compare, Allocator&gt;&amp;);
      void clear();

      // Observers

      key_compare key_comp() const;
      value_compare value_comp() const;

      // Map operations

      iterator find(const key_value&amp;);
      const_iterator find(const key_value&amp;) const;
      size_type count(const key_type&amp;) const;
      iterator lower_bound(const key_type&amp;);
      const_iterator lower_bound(const key_type&amp;) const;
      iterator upper_bound(const key_type&amp;);
      const_iterator upper_bound(const key_type&amp;) const;
      pair&lt;iterator, iterator&gt; equal_range(const key_type&amp;);
      pair&lt;const_iterator, const_iterator&gt;
        equal_range (const key_type&amp;) const;
};

  // Nonmember Map Operators

  template &lt;class Key, class T, class Compare, 
            class Allocator&gt;
  bool operator==(const map&lt;Key, T, Compare, Allocator&gt;&amp;,
                   const map&lt;Key, T, Compare, Allocator&gt;&amp;);

  template &lt;class Key, class T, class Compare, 
            class Allocator&gt;
  bool operator!=(const map&lt;Key, T, Compare, Allocator&gt;&amp;,
                  const map&lt;Key, T, Compare, Allocator&gt;&amp;);

  template &lt;class Key, class T, class Compare, 
            class Allocator&gt;
  bool operator&lt;(const map&lt;Key, T, Compare, Allocator&gt;&amp;,
                 const map&lt;Key, T, Compare, Allocator&gt;&amp;);

  template &lt;class Key, class T, class Compare, 
            class Allocator&gt;
  bool operator&gt;(const map&lt;Key, T, Compare, Allocator&gt;&amp;,
                 const map&lt;Key, T, Compare, Allocator&gt;&amp;);

  template &lt;class Key, class T, class Compare, 
            class Allocator&gt;
  bool operator&lt;=(const map&lt;Key, T, Compare, Allocator&gt;&amp;,
                  const map&lt;Key, T, Compare, Allocator&gt;&amp;);

  template &lt;class Key, class T, class Compare, 
            class Allocator&gt;
  bool operator&gt;=(const map&lt;Key, T, Compare, Allocator&gt;&amp;,
                  const map&lt;Key, T, Compare, Allocator&gt;&amp;);

  // Specialized Algorithms

  template &lt;class Key, class T, class Compare, 
            class Allocator&gt;
  void swap(map&lt;*Key,T,Compare,Allocator&gt;&amp;,
            map&lt;Key,T,Compare,Allocator&gt;&amp;);
}
</PRE></UL>
<A NAME="sec6"><H3>Constructors</H3></A>

<A NAME="idx836"></A><PRE>explicit <B>map</B>(const Compare&amp; comp = Compare(),
             const Allocator&amp; alloc = Allocator());</PRE>
<UL>
<P>Constructs an empty map that uses the relation <SAMP>comp</SAMP> to order keys, if it is supplied. The map uses the allocator <SAMP>alloc</SAMP> for all storage management.</P>
</UL>


<A NAME="idx837"></A><PRE>template &lt;class InputIterator&gt;
<B>map</B>(InputIterator start, InputIterator finish,
    const Compare&amp; comp = Compare(),
    const Allocator&amp; alloc = Allocator());</PRE>
<UL>
<P>Constructs a map containing values in the range <SAMP>[start, finish)</SAMP>. Creation of the new map is only guaranteed to succeed if the iterators <SAMP>start</SAMP> and <SAMP>finish</SAMP> return values of type <SAMP>pair&lt;class Key, class Value&gt;</SAMP> and all values of <SAMP>Key</SAMP> in the <SAMP>range[start, finish)</SAMP> are unique. The map uses the relation <SAMP>comp</SAMP> to order keys, and the allocator <SAMP>alloc</SAMP> for all storage management.</P>
</UL>


<A NAME="idx838"></A><PRE><B>map</B>(const map&lt;Key,T,Compare,Allocator&gt;&amp; x);</PRE>
<UL>
<P>Creates a new map by copying all pairs of <SAMP>key</SAMP> and <SAMP>value</SAMP> from <SAMP>x</SAMP>. </P>
</UL>

<A NAME="sec7"><H3>Allocators</H3></A>

<A NAME="idx839"></A><PRE>allocator_type <B>get_allocator</B>() const;</PRE>
<UL>
<P>Returns a copy of the allocator used by self for storage management.</P>
</UL>

<A NAME="sec8"><H3>Iterators</H3></A>

<A NAME="idx840"></A><PRE>iterator 
<B>begin</B>();</PRE>
<UL>
<P>Returns an <SAMP>iterator</SAMP> pointing to the first element stored in the map. <I>First&nbsp;</I> is defined by the map's comparison operator, <SAMP>Compare</SAMP>. </P>
</UL>


<A NAME="idx841"></A><PRE>const_iterator 
<B>begin</B>() const;</PRE>
<UL>
<P>Returns a <SAMP>const_iterator</SAMP> pointing to the first element stored in the map. </P>
</UL>


<A NAME="idx842"></A><PRE>iterator 
<B>end</B>();</PRE>
<UL>
<P>Returns an <SAMP>iterator</SAMP> pointing to the last element stored in the map; in other words, to the off-the-end value. </P>
</UL>


<A NAME="idx843"></A><PRE>const_iterator 
<B>end</B>() const;</PRE>
<UL>
<P>Returns a <SAMP>const_iterator</SAMP> pointing to the last element stored in the map. </P>
</UL>


<A NAME="idx844"></A><PRE>reverse_iterator 
<B>rbegin</B>();</PRE>
<UL>
<P>Returns a <SAMP>reverse_iterator</SAMP> pointing to the first element stored in the map. <I>First</I> is defined by the map's comparison operator, <SAMP>Compare</SAMP>. </P>
</UL>


<A NAME="idx845"></A><PRE>const_reverse_iterator 
<B>rbegin</B>() const;</PRE>
<UL>
<P>Returns a <SAMP>const_reverse_iterator</SAMP> pointing to the first element stored in the map. </P>
</UL>


<A NAME="idx846"></A><PRE>reverse_iterator 
<B>rend</B>();</PRE>
<UL>
<P>Returns a <SAMP>reverse_iterator </SAMP>pointing to the last element stored in the map; in other words, to the off-the-end value).</P>
</UL>


<A NAME="idx847"></A><PRE>const_reverse_iterator 
<B>rend</B>() const;</PRE>
<UL>
<P>Returns a <SAMP>const_reverse_iterator</SAMP> pointing to the last element stored in the map.</P>
</UL>

<A NAME="sec9"><H3>Member Operators</H3></A>

<A NAME="idx848"></A><PRE>map 
<B>operator=</B>(const map&lt;Key, T, Compare, Allocator&gt;&amp; x);</PRE>
<UL>
<P>Replaces the contents of <SAMP>*this</SAMP> with a copy of the map <SAMP>x</SAMP>. </P>
</UL>


<A NAME="idx849"></A><PRE>mapped_type&amp; 
<B>operator[]</B>(const key_type&amp; x);</PRE>
<UL>
<P>If an element with the key <SAMP>x</SAMP> exists in the map, then a reference to its associated value is returned. Otherwise the pair <SAMP>x,T()</SAMP> is inserted into the map and a reference to the default object <SAMP>T()</SAMP> is returned. </P>
</UL>

<A NAME="sec10"><H3>Member Functions</H3></A>

<A NAME="idx850"></A><PRE>void
<B>clear</B>();</PRE>
<UL>
<P>Erases all elements from the self.</P>
</UL>


<A NAME="idx851"></A><PRE>size_type 
<B>count</B>(const key_type&amp; x) const;</PRE>
<UL>
<P>Returns a <SAMP>1</SAMP> if a value with the key <SAMP>x</SAMP> exists in the map. Otherwise returns a <SAMP>0</SAMP>. </P>
</UL>


<A NAME="idx852"></A><PRE>bool 
<B>empty</B>() const;</PRE>
<UL>
<P>Returns <SAMP>true</SAMP> if the map is empty, <SAMP>false</SAMP> otherwise.</P>
</UL>


<A NAME="idx853"></A><PRE>pair&lt;iterator, iterator&gt; 
<B>equal_range</B> (const key_type&amp; x);</PRE>
<UL>
<P>Returns the pair <SAMP>(lower_bound(x), upper_bound(x))</SAMP>.</P>
</UL>


<A NAME="idx854"></A><PRE>pair&lt;const_iterator,const_iterator&gt; 
<B>equal_range</B> (const key_type&amp; x) const;</PRE>
<UL>
<P>Returns the pair <SAMP>(lower_bound(x), upper_bound(x))</SAMP>.</P>
</UL>


<A NAME="idx855"></A><PRE>void
<B>erase</B>(iterator position);</PRE>
<UL>
<P>Deletes the map element pointed to by the iterator <SAMP>position</SAMP>.</P>
</UL>


<A NAME="idx856"></A><PRE>void
<B>erase</B>(iterator start, iterator finish);</PRE>
<UL>
<P>If the iterators <SAMP>start</SAMP> and <SAMP>finish</SAMP> point to the same map and last is reachable from first, all elements in the range <SAMP>[start, finish)</SAMP> are deleted from the map.</P>
</UL>


<A NAME="idx857"></A><PRE>size_type 
<B>erase</B>(const key_type&amp; x);</PRE>
<UL>
<P>Deletes the element with the key value <SAMP>x</SAMP> from the map, if one exists. Returns <SAMP>1</SAMP> if <SAMP>x</SAMP> existed in the map, <SAMP>0</SAMP> otherwise. </P>
</UL>


<A NAME="idx858"></A><PRE>iterator 
<B>find</B>(const key_type&amp; x);</PRE>
<UL>
<P>Searches the map for a pair with the key value <SAMP>x</SAMP> and returns an <SAMP>iterator</SAMP> to that pair if it is found. If such a pair is not found the value <SAMP>end()</SAMP> is returned. </P>
</UL>


<A NAME="idx859"></A><PRE>const_iterator 
<B>find</B>(const key_type&amp; x) const; </PRE>
<UL>
<P>Same as <SAMP>find</SAMP> above but returns a <SAMP>const_iterator</SAMP>.</P>
</UL>


<A NAME="idx860"></A><PRE>pair&lt;iterator, bool&gt; 
<B>insert</B>(const value_type&amp; x);
iterator 
<B>insert</B>(iterator position, const value_type&amp; x);</PRE>
<UL>
<P>If a <SAMP>value_type</SAMP> with the same key as <SAMP>x</SAMP> is not present in the map, then <SAMP>x</SAMP> is inserted into the map. Otherwise, the pair is not inserted. A position may be supplied as a hint regarding where to do the insertion. If the insertion is done right after <SAMP>position</SAMP>, then it takes amortized constant time. Otherwise it takes<SAMP> O(log N)</SAMP> time. </P>
</UL>


<A NAME="idx861"></A><PRE>template &lt;class InputIterator&gt;
void 
<B>insert</B>(InputIterator start, InputIterator finish);</PRE>
<UL>
<P>Copies of each element in the range <SAMP>[start, finish)</SAMP> that possess a unique key (one not already in the map) are inserted into the map. The iterators <SAMP>start</SAMP> and <SAMP>finish</SAMP> must return values of <SAMP>type</SAMP> <SAMP>pair&lt;T1,T2&gt;</SAMP>. This operation takes approximately<SAMP> O(N*log(size()+N)) </SAMP>time. </P>
</UL>


<A NAME="idx862"></A><PRE>key_compare 
<B>key_comp</B>() const;</PRE>
<UL>
<P>Returns a function object capable of comparing key values using the comparison operation, <SAMP>Compare</SAMP>, of the current map. </P>
</UL>


<A NAME="idx863"></A><PRE>iterator 
<B>lower_bound</B>(const key_type&amp; x);</PRE>
<UL>
<P>Returns a reference to the first entry with a key greater than or equal to <SAMP>x</SAMP>.</P>
</UL>


<A NAME="idx864"></A><PRE>const_iterator 
<B>lower_bound</B>(const key_type&amp; x) const;</PRE>
<UL>
<P>Same as <SAMP>lower_bound</SAMP> above but returns a <SAMP>const_iterator</SAMP>. </P>
</UL>


<A NAME="idx865"></A><PRE>size_type 
<B>max_size</B>() const;</PRE>
<UL>
<P>Returns the maximum possible size of the map.   This size is only constrained by the number of unique keys that can be represented by the type <SAMP>Key</SAMP>. </P>
</UL>


<A NAME="idx866"></A><PRE>size_type 
<B>size</B>() const;</PRE>
<UL>
<P>Returns the number of elements in the map.</P>
</UL>


<A NAME="idx867"></A><PRE>void 
<B>swap</B>(map&lt;Key, T, Compare, Allocator&gt;&amp; x);</PRE>
<UL>
<P>Swaps the contents of the map <SAMP>x</SAMP> with the current map, <SAMP>*this</SAMP>. </P>
</UL>


<A NAME="idx868"></A><PRE>iterator 
<B>upper_bound</B>(const key_type&amp; x);</PRE>
<UL>
<P>Returns an iterator for the first entry with a key greater than <SAMP>x</SAMP>.</P>
</UL>


<A NAME="idx869"></A><PRE>const_iterator 
<B>upper_bound</B>(const key_type&amp; x) const;</PRE>
<UL>
<P>Same as <SAMP>upper_bound</SAMP> above, but returns a <SAMP>const_iterator.</SAMP></P>
</UL>


<A NAME="idx870"></A><PRE>value_compare 
<B>value_comp</B>() const;</PRE>
<UL>
<P>Returns a function object capable of comparing <SAMP>pair&lt;const Key, T&gt;</SAMP> values using the comparison operation,<SAMP> Compare</SAMP>, of the current map. This function is identical to <SAMP>key_comp</SAMP> for sets. </P>
</UL>

<A NAME="sec11"><H3>Nonmember Operators</H3></A>

<A NAME="idx871"></A><PRE>template &lt;class Key, class T, class Compare, class Allocator&gt;
bool <B>operator==</B>(const map&lt;Key, T, Compare, Allocator&gt;&amp; x,
                 const map&lt;Key, T, Compare, Allocator&gt;&amp; y);</PRE>
<UL>
<P>Returns <SAMP>true</SAMP> if all elements in <SAMP>x</SAMP> are element-wise equal to all elements in <SAMP>y</SAMP>, using<SAMP> (T::operator==)</SAMP>. Otherwise it returns <SAMP>false</SAMP>. </P>
</UL>


<A NAME="idx872"></A><PRE>template &lt;class Key, class T, class Compare, class Allocator&gt;
bool <B>operator!=</B>(const map&lt;Key, T, Compare, Allocator&gt;&amp; x,
                 const map&lt;Key, T, Compare, Allocator&gt;&amp; y);</PRE>
<UL>
<P>Returns<SAMP> !(x==y)</SAMP>. </P>
</UL>


<A NAME="idx873"></A><PRE>template &lt;class Key, class T, class Compare, class Allocator&gt;
bool <B>operator&lt;</B>(const map&lt;Key, T, Compare, Allocator&gt;&amp; x,
                const map&lt;Key, T, Compare, Allocator&gt;&amp; y);</PRE>
<UL>
<P>Returns <SAMP>true</SAMP> if <SAMP>x</SAMP> is lexicographically less than <SAMP>y</SAMP>. Otherwise, it returns <SAMP>false</SAMP>.</P>
</UL>


<A NAME="idx874"></A><PRE>template &lt;class Key, class T, class Compare, class Allocator&gt;
bool <B>operator&gt;</B>(const map&lt;Key, T, Compare, Allocator&gt;&amp; x,
                const map&lt;Key, T, Compare, Allocator&gt;&amp; y);</PRE>
<UL>
<P>Returns <SAMP>y &lt; x</SAMP>.</P>
</UL>


<A NAME="idx875"></A><PRE>template &lt;class Key, class T, class Compare, class Allocator&gt;
bool <B>operator&lt;=</B>(const map&lt;Key, T, Compare, Allocator&gt;&amp; x,
                const map&lt;Key, T, Compare, Allocator&gt;&amp; y);</PRE>
<UL>
<P>Returns <SAMP>!(y &lt; x)</SAMP>.</P>
</UL>


<A NAME="idx876"></A><PRE>template &lt;class Key, class T, class Compare, class Allocator&gt;
bool <B>operator&gt;=</B>(const map&lt;Key, T, Compare, Allocator&gt;&amp; x,
                const map&lt;Key, T, Compare, Allocator&gt;&amp; y);</PRE>
<UL>
<P>Returns <SAMP>!(x &lt; y)</SAMP>.</P>
</UL>

<A NAME="sec12"><H3>Specialized Algorithms</H3></A>

<A NAME="idx877"></A><PRE>template &lt;class Key, class T, class Compare, class Allocator&gt;
void <B>swap</B>(map&lt;Key, T, Compare, Allocator&gt;&amp; a,
           map&lt;Key, T, Compare, Allocator&gt;&amp; b);</PRE>
<UL>
<P>Swaps the contents of <SAMP>a</SAMP> and <SAMP>b</SAMP>.</P>
</UL>

<A NAME="sec13"><H3>Example</H3></A>

<UL><PRE>//
//  map.cpp
//

#include &lt;iostream&gt;    // for cout
#include &lt;map&gt;         // for map
#include &lt;string&gt;      // for string
#include &lt;utility&gt;     // for pair


typedef std::map&lt;std::string, int, std::less&lt;std::string&gt;,
                 std::allocator&lt;std::pair&lt;const std::string, 
                                int&gt; &gt; &gt;
        months_type;


// Print out a map.
inline std::ostream&amp;
operator&lt;&lt; (std::ostream &amp;out, const months_type &amp;m)
{
    for (months_type::const_iterator it = m.begin (); 
         it != m.end (); ++it)
        std::cout &lt;&lt; (*it).first &lt;&lt; " has " 
                  &lt;&lt; (*it).second &lt;&lt; " days\n";

    return out;
}


int main ()
{
    // Create a map of months and the number of days 
    // in the month.
    months_type months;

    typedef months_type::value_type value_type;

    // Put the months in the multimap.
    months.insert (value_type (std::string ("January"),   31));
    months.insert (value_type (std::string ("February"),  28));
    months.insert (value_type (std::string ("February"),  29));
    months.insert (value_type (std::string ("March"),     31));
    months.insert (value_type (std::string ("April"),     30));
    months.insert (value_type (std::string ("May"),       31));
    months.insert (value_type (std::string ("June"),      30));
    months.insert (value_type (std::string ("July"),      31));
    months.insert (value_type (std::string ("August"),    31));
    months.insert (value_type (std::string ("September"), 30));
    months.insert (value_type (std::string ("October"),   31));
    months.insert (value_type (std::string ("November"),  30));
    months.insert (value_type (std::string ("December"),  31));

    // Print out the months.  Second February is not present.
    std::cout &lt;&lt; months &lt;&lt; std::endl;

    // Find the Number of days in June.
    months_type::iterator p = months.find(std::string("June"));

    // Print out the number of days in June.
    if (p != months.end ())
        std::cout &lt;&lt; std::endl &lt;&lt; (*p).first &lt;&lt; " has "
                  &lt;&lt; (*p).second &lt;&lt; " days\n";
  
    return 0;
}


Program Output:
</PRE></UL>
<UL><PRE>April has 30 days
August has 31 days
December has 31 days
February has 28 days
January has 31 days
July has 31 days
June has 30 days
March has 31 days
May has 31 days
November has 30 days
October has 31 days
September has 30 days


June has 30 days
</PRE></UL>
<A NAME="sec14"><H3>Warnings</H3></A>
<P>Member function templates are used in all containers included in the Standard Template Library. For example, the constructor for <B><I>map</I></B> takes two templatized iterators:</P>

<UL><PRE>template &lt;class InputIterator&gt;
 map (InputIterator, InputIterator, 
      const Compare&amp; = Compare(),
      const Allocator&amp; = Allocator());
</PRE></UL>
<P><B><I>map</I></B> also has an insert function of this type. These functions, when not restricted by compiler limitations, allow you to use any type of input iterator as arguments. For compilers that do not support this feature, substitute functions allow you to use an iterator obtained from the same type of container as the one you are constructing (or calling a member function on), or you can use a pointer to the type of element you have in the container. </P>
<P>For example, if your compiler does not support member function templates, you can construct a <B><I>map</I></B> in the following two ways: </P>

<UL><PRE>map&lt;int, int, less&lt;int&gt; &gt;::value_type intarray[10];
map&lt;int, int, less&lt;int&gt; &gt; first_map(intarray, 
                                    intarray + 10);
map&lt;int, int, less&lt;int&gt; &gt; second_map(first_map.begin(),
                                     first_map.end());
</PRE></UL>
<P>You cannot construct a <B><I>map</I></B> this way:</P>

<UL><PRE>map&lt;long, long, less&lt;long&gt; &gt; long_map(first_map.begin(),
                                      first_map.end());
</PRE></UL>
<P>Since the <SAMP>long_map</SAMP> and <SAMP>first_map</SAMP> are not the same type.</P>
<P>If your compiler does not support template arguments, you must always  supply the <SAMP>Compare</SAMP> template argument and the <SAMP>Allocator</SAMP> template argument. For instance, you must write: </P>
<P><SAMP>map&lt;int, int, less&lt;int&gt;, allocator&lt;int&gt; &gt;</SAMP></P>
<P>instead of:</P>
<P><SAMP>map&lt;int, int&gt;</SAMP></P>
<A NAME="sec15"><H3>See Also</H3></A>
<P><B><I><A HREF="allocator.html">allocator</A></I></B>, <A HREF="containers.html">Containers</A>, <A HREF="iterators.html">Iterators</A>, <B><I><A HREF="multimap.html">multimap</A></I></B></P>
<A NAME="sec16"><H3>Standards Conformance</H3></A>
<P><I>ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 23.3.1</I></P>

<BR>
<HR>
<A HREF="map-h.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="mask-array.html"><IMG SRC="images/bnext.gif" WIDTH=20 HEIGHT=21 ALT="Next file" BORDER=O></A></BODY>
</HTML>
